import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('piniaCart', () => {
  let piniaCart = ref([])
  let piniaAddCart = (detailData, goods_id) => {
    let username = localStorage.getItem('token')
    let pdCart = piniaCart.value(item => item.goods.goods_id == goods_id)
    if (pdCart) {
      piniaCart.number++
    } else {
      piniaCart.value.push({
        username: username,
        num: 1,
        goods: detailData,
        id: Math.floor(Math.random() * 100000),
        checked: false,
      })
    }
  }
  return { piniaCart, piniaAddCart }

},
  {
    persist: true,
  },
)
